package com.ld.service;

import com.github.pagehelper.PageHelper;
import com.ld.mapper.TGeoTestMapper;
import com.ld.model.TGeoTest;
import com.ld.model.TGeoTestExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.math.BigDecimal;
import java.util.List;

@Service
public class TGeoTestService {

    @Autowired
    private TGeoTestMapper mapper;

    public List<TGeoTest> select(){
        List<TGeoTest> list = mapper.selectAll();
        System.out.println(list);
        TGeoTestExample example = new TGeoTestExample();
        example.createCriteria().andNAMEEqualTo("P1");
        List<TGeoTest> list1 = mapper.selectByExample(example);
        System.out.println(list1);
        return list;
    }
    public void insert(){
        TGeoTest tGeoTest = new TGeoTest();
        tGeoTest.setId(4);
        tGeoTest.setName("test");
        BigDecimal[] bigDecimals = new BigDecimal[]{new BigDecimal(23.0),new BigDecimal(123.2)};
        tGeoTest.setShape(bigDecimals);
        mapper.insert(tGeoTest);
    }
    public void update(){
        TGeoTestExample example = new TGeoTestExample();
        example.createCriteria().andNAMEEqualTo("P1");
        List<TGeoTest> list1 = mapper.selectByExample(example);
        TGeoTest updateParam = mapper.selectByPrimaryKey(4);
        BigDecimal[] bigDecimals = new BigDecimal[]{new BigDecimal(1.0),new BigDecimal(1.2)};
        updateParam.setShape(bigDecimals);
        mapper.updateByPrimaryKey(updateParam);
    }

    public List<TGeoTest> listPage(){
        PageHelper.startPage(1,1);
        List<TGeoTest> list = mapper.selectAll();
        System.out.println(list);
        return list;
    }
}
